using System;
using System.Collections.Generic;
using System.Text;

namespace WOWEquipOptimizer.Druid
{
    class Restoration : Healer
    {
        public Restoration()
            : base()
        {
            m_Base = new List<Attribute>();
            m_Base.Add(new Attribute(AttributeName.Mana, 2100));
            m_Base.Add(new Attribute(AttributeName.Health, 3400));
            m_Base.Add(new Attribute(AttributeName.Stamina, 85));
            m_Base.Add(new Attribute(AttributeName.Intellect, 115));
            m_Base.Add(new Attribute(AttributeName.Spirit, 155));
            m_Base.Add(new Attribute(AttributeName.CritSpellRating, 1.85f * CritSpellRating));
            foreach (Attribute attr in m_Base)
            {
                handleAttribute(attr);
            }
        }
        // mana, int, spirit, +heal, crit,spellhaste, mp5,health
        public override void handleAttribute(Attribute attr)
        {
            switch (attr.Type)
            {
                case AttributeName.Intellect:
                    m_Equip[AttributeName.Mana] += attr.Value * (HasBlessingOfKings ? 1.1f : 1.0f) * 15;
                    m_Equip[AttributeName.Intellect] += attr.Value * (HasBlessingOfKings ? 1.1f : 1.0f);
                    m_Equip[AttributeName.CritSpellRating] += (attr.Value * (HasBlessingOfKings ? 1.1f : 1.0f) / 80) * CritSpellRating;
                    break;
                case AttributeName.Spirit:
                    m_Equip[attr.Type] += attr.Value * (HasBlessingOfKings ? 1.1f : 1.0f) * 1.15f;
                    break;
                case AttributeName.SpellDamage:
                case AttributeName.Healing:
                    m_Equip[AttributeName.Healing] += attr.Value;
                    break;
                default:
                    base.handleAttribute(attr);
                    break;
            }
        }
        // mana, int, spirit, +heal, crit, spellhaste, mp5
        public override float evaluateTF()
        {
            float runtime = 600;
            float time = runtime;
            float HT6 = 43 / 70f;
            float HT6cost = 335;
            float HT6heal = 818;
            float spellcrit = m_Equip[AttributeName.CritSpellRating] / CritSpellRating;
            float manaregic = m_Equip[AttributeName.MP5] / 5f + ((m_Equip[AttributeName.Spirit] / 4.5f + 17) * 0.15f) / 2f;
            float manaregooc = manaregic + (m_Equip[AttributeName.Spirit] / 4.5f + 17) / 2f;
            float HT6mana = HT6cost * 0.9f - manaregic * 3;
            float count = (float)Math.Floor(m_Equip[AttributeName.Mana] / HT6mana);
            float castuseratio = (manaregooc * 3.0f) / HT6mana;
            time -= count * 3f + Math.Max(5 * castuseratio, 5);
            time = Math.Max(time, 0);
            float regtime = 0;
            if (this.SpecialValues.Contains("28444208"))
            {
                HT6heal += 136f;
            }
            if (time > 0)
            {
                regtime = time / (castuseratio + 1);
                regtime = Math.Min(regtime, 0.3f * runtime);
                time -= regtime;
            }
            count += (float)Math.Floor((regtime * manaregooc) / HT6mana);
            count = Math.Min(count, (runtime - regtime) / 3f);
            float HealHT6 = 1.1f * count * (HT6heal + m_Equip[AttributeName.Healing] * 1.2f * HT6); // no healcrits
            return CondFactor * HealHT6 / runtime;
        }
        public override List<Item> filterEquip(List<Item> input)
        {
            input = base.filterEquip(input);
            List<Item> retval = new List<Item>();
            foreach (Item item in input)
            {
                if ((item.AllowableClasses & CharacterClass.Druid) == 0) continue;
                if (item.GetType() == typeof(Weapon))
                {
                    Weapon weapon = (Weapon)item;
                    if (weapon.WeaponSlot == WeaponSlot.Ranged && weapon.Type != WeaponType.Idol) continue;
                    if (weapon.Type == WeaponType.Sword || weapon.Type == WeaponType.Axe) continue;
                    if (weapon.TwoHand && (weapon.Type != WeaponType.Staff || weapon.Type != WeaponType.Mace)) continue;
                    if (weapon.WeaponSlot == WeaponSlot.OffHand) continue;
                }
                else if (item.GetType() == typeof(Armor))
                {
                    Armor armor = (Armor)item;
                    if ((armor.Type & ArmorProficiency.Leather) == 0) continue;
                }
                if (SetBlacklist.Contains(item.Set.Name)) continue;
                if (ItemBlacklist.Contains(item.Name)) continue;
                retval.Add(item);
            }
            return handleWhiteList(retval);
        }
        public override bool evaluateBuild(int[] build)
        {
            if (build[2] >= 35)
            {
                return true;
            }
            else return false;
        }
    }
}
